package cn.taketoday.live.component.task;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

import cn.taketoday.live.config.GlobalData;
import cn.taketoday.live.data.user.UserMedal;
import cn.taketoday.live.http.BilibiliHttpRequests;
import cn.taketoday.live.http.HttpOtherData;
import cn.taketoday.live.service.SettingsService;
import cn.taketoday.live.tools.CurrencyTools;

@Component("dosignTask")
public class DoSignTask {
  @Autowired
  private SettingsService setService;
  private static Logger LOGGER = LogManager.getLogger(DoSignTask.class);

  public void dosign() {
    if (!StringUtils.isEmpty(GlobalData.USERCOOKIE)) {
      BilibiliHttpRequests.signIn();
    }
    else {
      LOGGER.error("定时任务抛出： 未登录 签到失败");
    }
  }

  public void clockin() {
    if (!StringUtils.isEmpty(GlobalData.USERCOOKIE)) {
      List<UserMedal> userMedals = CurrencyTools.getAllUserMedals();
      int max = CurrencyTools.clockIn(userMedals);
      if (max == userMedals.size()) {
        HttpOtherData.httpPOSTSetClockInRecord();
      }
    }
    else {
      LOGGER.error("定时任务抛出： 未登录 打卡失败");
    }
  }

  public void test() {
    System.err.println("test");
  }
}
